/**
 * Created by shidaiapp on 2017/9/29.
 */

import actionUrls from "../../../../api/ApiUrls"
import ApiBase from "../../../../api/moudles/ApiBase"
import {isEmpty} from "../../../js/commonUtils";
/**
 * 初始化
 * @param self
 * @param tiyData
 */
export const init = (self, tiyData) => {
  //resetForm(self, tiyData);
  tiyData.tPage.total = 1;
  tiyData.tPage.startIndex = 0;
  tiyData.tPage.stepNumber = 40;
  tiyData.tPage.currentPage = 1;
  tiyData.tParams.searchParams.categoryCode = "";
  tiyData.tParams.searchParams.categoryLevel = 0;
  tiyData.tParams.searchParams.startCreatedate = "";
  tiyData.tParams.searchParams.endCreatedate = "";
  tiyData.tParams.searchParams.productCode = "";
 };

/**
 * 从服务器请求列表
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const webList = (self, tiyData) => {
  self.$Spin.show();
  let startDate = isEmpty(tiyData.tParams.searchParams.startCreatedate)?null:self.$tiyQueryTime(new Date(tiyData.tParams.searchParams.startCreatedate).getTime());
  let endDate = isEmpty(tiyData.tParams.searchParams.endCreatedate)?null:self.$tiyQueryTime(new Date(tiyData.tParams.searchParams.endCreatedate).getTime())
  self.$apiAnalysis.cartList({
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "startCreatedate": startDate,
    "endCreatedate": endDate,
    "productCode": tiyData.tParams.searchParams.productCode,
    "categoryCode": tiyData.tParams.searchParams.categoryCode,
    "categoryLevel": tiyData.tParams.searchParams.categoryLevel,
  }).then(function (response) {
    self.$Spin.hide();
    if (response.success) {
      tiyData.tData.productOrderList.length = 0;
      let productOrderPage = response.result;
      tiyData.tPage.total = productOrderPage.total;
      tiyData.tPage.stepNumber = productOrderPage.pageSize;
      productOrderPage.list.forEach(
        function (item) {
          tiyData.tData.productOrderList.push(item);
        }
      );
      if (0 == tiyData.tData.productOrderList.length) {
        tiyData.tData.productOrderList.splice(0, tiyData.tData.productOrderList.length);
      }
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};

